unit dmxs_SendInformMaster;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dmModule, FR_DSet, FR_DBSet, DB, math,ADODB;

type
  Tdtmxs_SendInformMaster = class(TdtmModule)
    adsMasterEditBillID: TStringField;
    adsMasterEditBillNo: TStringField;
    adsMasterEditBillType: TStringField;
    adsMasterEditBillDate: TDateTimeField;
    adsMasterEditDeptID: TStringField;
    adsMasterEditStockID: TStringField;
    adsMasterEditCustID: TStringField;
    adsMasterEditCurrencyID: TStringField;
    adsMasterEditExchangeRate: TFloatField;
    adsMasterEditLinkMan: TStringField;
    adsMasterEditOperatorID: TStringField;
    adsMasterEditFollowerID: TStringField;
    adsMasterEditSettleID: TStringField;
    adsMasterEditTransType: TStringField;
    adsMasterEditFetchType: TStringField;
    adsMasterEditFetchAddress: TStringField;
    adsMasterEditHasCheck: TBooleanField;
    adsMasterEditChecker: TStringField;
    adsMasterEditCheckTime: TDateTimeField;
    adsMasterEditWriter: TStringField;
    adsMasterEditWriteTime: TDateTimeField;
    adsMasterEditModifier: TStringField;
    adsMasterEditModifyTime: TDateTimeField;
    adsMasterEditRemark: TStringField;
    adsMasterBillID: TStringField;
    adsMasterBillNo: TStringField;
    adsMasterBillType: TStringField;
    adsMasterBillDate: TDateTimeField;
    adsMasterDeptID: TStringField;
    adsMasterStockID: TStringField;
    adsMasterCustID: TStringField;
    adsMasterCurrencyID: TStringField;
    adsMasterExchangeRate: TFloatField;
    adsMasterLinkMan: TStringField;
    adsMasterOperatorID: TStringField;
    adsMasterFollowerID: TStringField;
    adsMasterSettleID: TStringField;
    adsMasterTransType: TStringField;
    adsMasterFetchType: TStringField;
    adsMasterFetchAddress: TStringField;
    adsMasterHasCheck: TBooleanField;
    adsMasterChecker: TStringField;
    adsMasterCheckTime: TDateTimeField;
    adsMasterWriter: TStringField;
    adsMasterWriteTime: TDateTimeField;
    adsMasterModifier: TStringField;
    adsMasterModifyTime: TDateTimeField;
    adsMasterRemark: TStringField;
    adsMasterStockName: TStringField;
    adsMasterCustCode: TStringField;
    adsMasterCustShortName: TStringField;
    adsMasterCurrencyName: TStringField;
    adsMasterOperatorName: TStringField;
    adsMasterFollowerName: TStringField;
    adsMasterSettleName: TStringField;
    adsMasterTransTypeName: TStringField;
    adsMasterFetchTypeName: TStringField;
    adsDetail: TADODataSet;
    adsDetailID: TStringField;
    adsDetailBillID: TStringField;
    adsDetailBillDetailNo: TStringField;
    adsDetailProductID: TStringField;
    adsDetailProductCode: TStringField;
    adsDetailColorName: TStringField;
    adsDetailNumber: TBCDField;
    adsDetailUnitID: TStringField;
    adsDetailPrice: TBCDField;
    adsDetailMoney: TBCDField;
    adsDetailWriter: TStringField;
    adsDetailWriteTime: TDateTimeField;
    adsDetailModifier: TStringField;
    adsDetailModifyTime: TDateTimeField;
    adsDetailRemark: TStringField;
    res_DeptCustSupply: TADODataSet;
    res_Unit: TADODataSet;
    res_Currency: TADODataSet;
    res_Employee: TADODataSet;
    adsMasterEditres_CustName: TStringField;
    adsMasterEditres_CurrencyName: TStringField;
    adsMasterEditres_OperatorName: TStringField;
    adsMasterEditres_FollowerName: TStringField;
    res_BaseInfo: TADODataSet;
    adsMasterEditres_SettleName: TStringField;
    adsMasterEditres_TransTypeName: TStringField;
    adsMasterEditres_FetchTypeName: TStringField;
    adsDetailres_UnitName: TStringField;
    adsBrowseDetail: TADODataSet;
    res_Stock: TADODataSet;
    adsMasterEditres_StockName: TStringField;
    adsSendInformType: TADODataSet;
    adsDetailOrderNo: TStringField;
    adsDetailOrderDetailNo: TStringField;
    frdsDetail: TfrDBDataSet;
    adsDetailProductName: TStringField;
    adsDetailSpecs: TStringField;
    adsMasterEditExportType: TStringField;
    adsMasterExportType: TStringField;
    adsMasterBillFlowName: TStringField;
    adsMasterEditReview: TBooleanField;
    adsMasterEditHasReview: TBooleanField;
    adsMasterEditReviewer: TStringField;
    adsMasterEditReviewTime: TDateTimeField;
    adsMasterEditReviewPass: TStringField;
    adsMasterEditReviewMemo: TStringField;
    res_SendReviewPass: TADODataSet;
    adsMasterEditres_ReviewPassName: TStringField;
    adsMasterReview: TBooleanField;
    adsMasterHasReview: TBooleanField;
    adsMasterReviewer: TStringField;
    adsMasterReviewTime: TDateTimeField;
    adsMasterReviewPass: TStringField;
    adsMasterReviewMemo: TStringField;
    adsMasterReviewPassName: TStringField;
    adsDetailSendNumber: TFloatField;
    adsDetailSendTime: TDateTimeField;
    adsDetailBatchNo: TStringField;
    adsMasterEditMaxBillDetailNo: TIntegerField;
    adsMasterMaxBillDetailNo: TIntegerField;
    adsUserCompany: TADODataSet;
    res_ProcessType: TADODataSet;
    adsDetailProcessID: TStringField;
    adsDetailres_ProcessName: TStringField;
    adsMasterEditres_DeptName: TStringField;
    adsMasterHelperCode: TStringField;
    adsMasterEditHasCreateTask: TBooleanField;
    adsMasterEditCheckMan: TStringField;
    adsMasterEditCheckManName: TStringField;
    adsMasterEditReviewMan: TStringField;
    adsMasterEditReviewManName: TStringField;
    adsMasterEditApproveMan: TStringField;
    adsMasterEditApproveManName: TStringField;
    adsMasterEditHasApprove: TBooleanField;
    adsMasterEditApprover: TStringField;
    adsMasterEditApproveTime: TDateTimeField;
    adsMasterEditApprovePass: TStringField;
    adsMasterEditApproveMemo: TStringField;
    adsMasterHasApprove: TBooleanField;
    adsMasterApprover: TStringField;
    adsMasterApproveTime: TDateTimeField;
    adsDetailColorCode: TStringField;
    adsDetailColorID: TStringField;
    res_FetchType: TADODataSet;
    adsDetailGradeID: TStringField;
    res_ProductGrade: TADODataSet;
    adsDetailres_GradeName: TStringField;
    adsDetailPieceCount: TFloatField;
    adsMasterEditBillFlow: TStringField;
    adsMasterBillFlow: TStringField;
    adsDetailSendStatus: TStringField;
    adsDetailsalemoney: TFloatField;
    adsDetailSalePrice: TFloatField;
    adsBrowseDetailID: TStringField;
    adsBrowseDetailBillID: TStringField;
    adsBrowseDetailBillDetailNo: TStringField;
    adsBrowseDetailOrderNo: TStringField;
    adsBrowseDetailOrderDetailNo: TStringField;
    adsBrowseDetailProcessID: TStringField;
    adsBrowseDetailres_ProcessName: TStringField;
    adsBrowseDetailProductID: TStringField;
    adsBrowseDetailProductCode: TStringField;
    adsBrowseDetailProductName: TStringField;
    adsBrowseDetailSpecs: TStringField;
    adsBrowseDetailBatchNo: TStringField;
    adsBrowseDetailGradeID: TStringField;
    adsBrowseDetailres_GradeName: TStringField;
    adsBrowseDetailColorID: TStringField;
    adsBrowseDetailColorCode: TStringField;
    adsBrowseDetailColorName: TStringField;
    adsBrowseDetailNumber: TBCDField;
    adsBrowseDetailPieceCount: TFloatField;
    adsBrowseDetailUnitID: TStringField;
    adsBrowseDetailres_UnitName: TStringField;
    adsBrowseDetailPrice: TBCDField;
    adsBrowseDetailMoney: TBCDField;
    adsBrowseDetailSendNumber: TFloatField;
    adsBrowseDetailSendTime: TDateTimeField;
    adsBrowseDetailWriter: TStringField;
    adsBrowseDetailWriteTime: TDateTimeField;
    adsBrowseDetailModifier: TStringField;
    adsBrowseDetailModifyTime: TDateTimeField;
    adsBrowseDetailRemark: TStringField;
    adsBrowseDetailSendStatus: TStringField;
    res_TransType: TADODataSet;
    adsDetailSendPieceCount: TFloatField;
    adsSendInformDetail: TADODataSet;
    StringField1: TStringField;
    StringField2: TStringField;
    adsSendInformDetailBillNo: TStringField;
    adsSendInformDetailBillType: TStringField;
    adsSendInformDetailBillDate: TDateTimeField;
    adsSendInformDetailExportType: TStringField;
    adsSendInformDetailDeptID: TStringField;
    adsSendInformDetailStockID: TStringField;
    adsSendInformDetailStockName: TStringField;
    adsSendInformDetailCustID: TStringField;
    adsSendInformDetailCustCode: TStringField;
    adsSendInformDetailCustShortName: TStringField;
    adsSendInformDetailHelperCode: TStringField;
    adsSendInformDetailCurrencyID: TStringField;
    adsSendInformDetailCurrencyName: TStringField;
    adsSendInformDetailExchangeRate: TFloatField;
    adsSendInformDetailTransType: TStringField;
    adsSendInformDetailTransTypeName: TStringField;
    adsSendInformDetailFetchAddress: TStringField;
    StringField3: TStringField;
    StringField4: TStringField;
    StringField5: TStringField;
    StringField7: TStringField;
    adsSendInformDetailProcessName: TStringField;
    StringField9: TStringField;
    StringField10: TStringField;
    StringField11: TStringField;
    StringField12: TStringField;
    StringField13: TStringField;
    StringField14: TStringField;
    StringField16: TStringField;
    StringField17: TStringField;
    StringField18: TStringField;
    BCDField1: TBCDField;
    FloatField1: TFloatField;
    StringField19: TStringField;
    adsSendInformDetailUnitName: TStringField;
    FloatField7: TFloatField;
    BCDField2: TBCDField;
    BCDField3: TBCDField;
    adsSendInformDetailSendStatusName: TStringField;
    FloatField8: TFloatField;
    DateTimeField1: TDateTimeField;
    StringField23: TStringField;
    adsSendInformDetailSendStatus: TStringField;
    adsSendInformDetailGradeName: TStringField;
    adsBrowseDetailSendPieceCount: TFloatField;
    procedure adsDetailNewRecord(DataSet: TDataSet);
    procedure adsDetailNumberChange(Sender: TField);
    procedure adsDetailPriceChange(Sender: TField);
    procedure adsMasterEditCurrencyIDChange(Sender: TField);
  private
    { Private declarations }
  protected
    procedure ModuleInit;override;
  public
    { Public declarations }
    procedure OpenEditDataSet;override;
  end;

var
  dtmxs_SendInformMaster: Tdtmxs_SendInformMaster;
  FOnChangeFlag: Integer = 0;

implementation

uses uCalcData, uConst, uShare, uSQL, dmConnect;

{$R *.dfm}

{ Tdtmxs_SendInformMaster }

procedure Tdtmxs_SendInformMaster.ModuleInit;
begin
  inherited;
  FUniqueTable := 'xs_SendInformMaster';
  FMasterKeyField := 'BillID';
end;

procedure Tdtmxs_SendInformMaster.OpenEditDataSet;
begin
  FMasterEditTable := 'xs_SendInformMaster';
  FMasterKeyField := 'BillID';
  inherited;

end;

procedure Tdtmxs_SendInformMaster.adsDetailNewRecord(DataSet: TDataSet);
begin
  inherited;
  SetWriteInfo(DataSet);
end;

procedure Tdtmxs_SendInformMaster.adsDetailNumberChange(Sender: TField);
begin
  inherited;
  if (adsDetail.State in [dsInsert, dsEdit]) and (FOnChangeFlag=0) then
  try
    FOnChangeFlag := 1;
    adsDetail.FieldByName('Money').ReadOnly := false;
    adsDetail.FieldByName('Money').AsFloat := roundto(adsDetail.FieldByName('Number').AsFloat*adsDetail.FieldByName('Price').AsFloat,-2);
    adsDetail.FieldByName('Money').ReadOnly := true;
  finally
    FOnChangeFlag := 0;
  end;
end;

procedure Tdtmxs_SendInformMaster.adsDetailPriceChange(Sender: TField);
begin
  inherited;
  if (adsDetail.State in [dsInsert, dsEdit]) and (FOnChangeFlag=0) then
  try
    FOnChangeFlag := 1;
    adsDetail.FieldByName('Money').ReadOnly := false;
    adsDetail.FieldByName('Money').AsFloat := roundto(adsDetail.FieldByName('Number').AsFloat*adsDetail.FieldByName('Price').AsFloat,-2);
    adsDetail.FieldByName('Money').ReadOnly := true;
  finally
    FOnChangeFlag := 0;
  end;
end;

procedure Tdtmxs_SendInformMaster.adsMasterEditCurrencyIDChange(
  Sender: TField);
begin
  inherited;
  if (adsMasterEdit.State in [dsInsert, dsEdit]) and (Sender.AsString<>'') then
  begin
    adsMasterEdit.FieldByName('ExchangeRate').ReadOnly := False;
    adsMasterEdit.FieldByName('ExchangeRate').AsFloat :=
      frExecSQL('Select ExchangeRate from da_Currency where ID=' + QuotedStr(Sender.AsString));
  end;
end;

end.
